package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api("订单管理接口")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result conditionSearch(OrdersPageQueryDTO dto){
       PageResult result= ordersService.search(dto);
        return Result.success(result);
    }
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result statistics(){
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO result = ordersService.statistics();
        return Result.success(result);
    }
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result  confirm(@RequestBody OrdersConfirmDTO dto){
        log.info("接单{}",dto);
        ordersService.confirm(dto);
        return Result.success();
    }
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单{}",dto);
        ordersService.rejection(dto);
        return Result.success();
    }
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        log.info("取消订单{}",dto);
        ordersService.cancle(dto);
        return Result.success();
    }
    @ApiOperation("派送订单")
    @PutMapping("delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("派送订单{}",id);
        ordersService.delivery(id);
        return  Result.success();
    }
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        log.info("完成订单{}",id);
        ordersService.complete(id);
        return Result.success();
    }
}
